//
//  VisitorTableViewController.swift
//  weibo10
//
//  Created by 周荣硕 on 16/1/9.
//  Copyright © 2016年 grgbanking. All rights reserved.
//

import UIKit

class VisitorTableViewController: UITableViewController {

    //用户登录标识
//    private var userLogon = false
    private var userLogon = UserAccountViewModel.sharedUserAccount.userLogon
    /// 访客视图
    var visitorView: VisitorView?
//    lazy var visitorView: VisitorView? = VisitorView()
    
    override func loadView() {
        
        userLogon ? super.loadView() : setupVisitorView()
        
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        print(visitorView)
    }
    
    private func setupVisitorView(){
        //替换根视图
    
        visitorView = VisitorView()
        view = visitorView
        
        //添加监听方法
        
        visitorView?.registerButton.addTarget(self, action: "visitorViewDidRegister", forControlEvents: .TouchUpInside)
        visitorView?.loginButton.addTarget(self, action: "visitorViewDidLogin", forControlEvents: .TouchUpInside)
       
        //设置导航栏
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visitorViewDidRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "visitorViewDidLogin")
    }
}

extension VisitorTableViewController {

    func visitorViewDidLogin() {
//        print("登录")
        let vc = OAuthViewController()
        let nav = UINavigationController(rootViewController: vc)
        
        presentViewController(nav, animated: true, completion: nil)
    }
    func visitorViewDidRegister() {
        print("注册")
    }
}